package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Role;
import com.itheima.health.vo.RoleVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface RoleMapper extends BaseMapper<Role> {

    //根据rid删除中间表数据
    @Delete("delete from t_role_permission where role_id = #{rid}")
    void deletePidByRid(@Param("rid") Integer rid);

    //根据角色id往中间表添加权限id
    @Insert("INSERT INTO t_role_permission VALUES(#{rid},#{pid})")
    void insertPidByRid(@Param("rid") Integer rid, @Param("pid") Integer pid);

    //根据id查询角色信息
    @Select("select id,name,keyword,description from t_role where id = #{rid}")
    RoleVO findByRid(@Param("rid") Integer rid);

    //中间表   根据角色id查权限id
    @Select("SELECT permission_id FROM t_role_permission WHERE role_id=#{rid}")
    Integer[] findPids(@Param("rid") Integer rid);

    @Select("SELECT menu_id FROM t_role_menu WHERE role_id=#{rid}")
    Integer[] findMids(@Param("rid") Integer rid);

    @Delete("delete from t_role_menu where role_id = #{rid}")
    void deleteMidByRid(@Param("rid") Integer rid);

    @Insert("INSERT INTO t_role_menu VALUES(#{rid},#{mid})")
    void insertMidByRid(@Param("rid") Integer rid, @Param("mid") Integer mid);
}
